package com.mission.listview

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.mission.listview.databinding.ActivityMainBinding

//import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    private val fruitList = ArrayList<Fruit>()
    private lateinit var fruitAdapter: FruitAdapter
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
//        setContentView(R.layout.activity_main)
        setContentView(binding.root)

        initFruits()
        fruitAdapter = FruitAdapter(this, R.layout.item_fruit, fruitList)
//        list_view.adapter = fruitAdapter
        binding.listView.adapter = fruitAdapter
    }

    /**
     * 初始化说过数据
     */
    private fun initFruits() {
        repeat(2) {
            fruitList.add(Fruit("Apple", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Banana", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Watermelon", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Orange", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Pear", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Grape", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Pineapple", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Strawberry", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Cherry", R.mipmap.ic_launcher))
            fruitList.add(Fruit("Mango", R.mipmap.ic_launcher))
        }
    }
}